import { useAppStore } from "@/stores/app";
const appStore = useAppStore();

import i18n from "@/locale";
const { t } = i18n.global;
// 公共过滤器
export function filterEmpty(val) {
	let _result = "-";
	if (!val) {
		return _result;
	}
	_result = val;
	return _result;
}
/**
 * 商户分类
 */
export function merCategoryFilter(status) {
	if (!status) {
		return "";
	}
	let arrayList = appStore.merchantClassify;
	let array = arrayList.filter((item) => status === item.id);
	if (array.length) {
		return array[0].name;
	} else {
		return "";
	}
}

/**
 * 商铺类型
 */
export function merchantTypeFilter(status) {
	if (!status) {
		return "";
	}
	let arrayList = appStore.merchantType;
	let array = arrayList.filter((item) => status === item.id);
	if (array.length) {
		return array[0].name;
	} else {
		return "";
	}
}

/**
 * 商户创建类型
 */
export function merCreateTypeFilter(status) {
	const statusMap = {
		admin: "管理员创建",
		apply: "商户入驻申请",
	};
	return statusMap[status];
}

/**
 * 商户类别
 */
export function selfTypeFilter(status) {
	const statusMap = {
		true: "自营",
		false: "非自营",
	};
	return statusMap[status];
}

/**
 * 日期去掉时间
 */
export function dateFormat(value) {
	if (!value) {
		return "";
	}
	return value.split(" ")[0];
}

/**
 * 退款状态
 */
export function refundStatusFilter(status) {
	const statusMap = {
		0: t(`message.tips.stay`),
		1: t(`message.tips.noadopt`),
		2: t(`page.users.userReturnList.refunding`),
		3: t(`page.users.userReturnList.refunded`),
	};
	return statusMap[status];
}

/**
 * 订单状态
 */
export function orderStatusFilter(status) {
	const statusMap = [
		t(`page.user.orderStatus[1].name`),
		t(`page.user.orderStatus[2].name`),
		t(`page.user.orderStatus[6].name`),
		t(`page.user.orderStatus[5].name`),
	];

	return statusMap[status];
}
